package com.dynamoc.cglib;
import com.dynamoc.aspect.LogForService;
import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.InvocationHandler;

import java.lang.reflect.Method;

public class CglibDynamic {
    public Object getProxyObject(Object tagetClass){
        Object o = Enhancer.create(tagetClass.getClass(), new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                LogForService logForService = new LogForService();
                logForService.beforeStrengthen();
                Object invoke = method.invoke(tagetClass, args);
                logForService.afterStrengthen();
                return invoke;

            }
        });
        return o;

    }
}
